package com.fenxiangle.yueding.feature.extension.presenter;

import com.fenxiangle.yueding.entity.bo.AliPayBo;
import com.fenxiangle.yueding.entity.bo.ExtensionBo;
import com.fenxiangle.yueding.feature.extension.contract.ExtensionContract;
import com.fenxiangle.yueding.feature.extension.login.DaggerExtensionPresenterComponent;

import org.json.JSONObject;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ExtensionPresenter implements ExtensionContract.Presenter{

    ExtensionContract.View mView;

    @Inject

    ExtensionContract.Model mModel;


    public ExtensionPresenter(ExtensionContract.View mView) {
        this.mView = mView;
        DaggerExtensionPresenterComponent.create().inject(this);
    }
    @Override
    public void user_Extension_Center() {
        mModel.user_Extension_Center().compose(mView.<ExtensionBo>bindToLife()).subscribe(new Observer<ExtensionBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(ExtensionBo s) {
                mView.dismissLoading();
                mView.ShowData(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void recharge_member(JSONObject jsonObject) {
        mModel.recharge_member(jsonObject).compose(mView.<AliPayBo>bindToLife()).subscribe(new Observer<AliPayBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(AliPayBo s) {
                mView.dismissLoading();
                mView.showAliPayBo(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void user_forward(JSONObject jsonObject) {
        mModel.user_forward(jsonObject).compose(mView.<AliPayBo>bindToLife()).subscribe(new Observer<AliPayBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(AliPayBo s) {
                mView.dismissLoading();
                mView.showWeiChatData(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void is_set_pwd() {
        mModel.is_set_pwd().compose(mView.<String>bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.dismissLoading();
                mView.showPwd(s);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void user_payment_set(JSONObject jsonObject) {
        mModel.user_payment_set(jsonObject).compose(mView.<String>bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.dismissLoading();
                mView.user_payment_set();

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void start() {

    }
}
